﻿/*
 * 由SharpDevelop创建。
 * 用户： Administrator
 * 日期: 2024/12/1
 * 时间: 17:31
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using System.IO;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace music
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			string inipath=Directory.GetCurrentDirectory()+"\\setting.ini"; 
			int x=int.Parse(iniHelper.Read("Music","left",inipath));
			int y=int.Parse(iniHelper.Read("Music","top",inipath));
			this.Location=new Point(x,y);
			 
			int w=int.Parse(iniHelper.Read("Music","width",inipath));
			int h=int.Parse(iniHelper.Read("Music","height",inipath));
			this.Size=new Size(w,h);
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		void Timer1Tick(object sender, EventArgs e)
		{
			string inipath=Directory.GetCurrentDirectory()+"\\setting.ini"; 
			string color=iniHelper.Read("Topbar","backcolor",inipath);
			this.BackColor =ColorTranslator.FromHtml(color);
		}
		void Label1MouseClick(object sender, MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Left) {//左键
				try {
					string inipath=Directory.GetCurrentDirectory()+"\\setting.ini"; 
					string path =iniHelper.Read("music","path",inipath);
					
					string[] files = Directory.GetFiles(path, "*.mp3");
					string t="";
					foreach (string file in files)
					{
						t+=file+"\n";
					}
					 string[] line=t.Split('\n');
					Random rd = new Random();
		            int i = rd.Next(0,line.Length);
		            string  musicpath=line[i];
		            
		            
		            musicplay mp=new musicplay();
					mp.PlayMusic(musicpath);
					
					label1.Text=Path.GetFileNameWithoutExtension(musicpath);
					//label5.Width= TextRenderer.MeasureText(label5.Text, label5.Font).Width; 
				} catch (Exception) {
					MessageBox.Show("请设置歌曲文件夹路径，并且保证含有mp3格式歌曲");
				}	 
			} 
			//右键
    		else if(e.Button == MouseButtons.Right){
				musicplay mp=new musicplay();
				mp.StopMusic();
			} 
		}
	}
}
